package com.ruoyi.wm.controller;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.wm.domain.WmApparatusOutstorageList;
import com.ruoyi.wm.service.IWmApparatusOutstorageListService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 医疗器械出库记录Controller
 * 
 * @author hpf
 * @date 2021-11-25
 */
@Controller
@RequestMapping("/wm/apparatus_outstorage")
public class WmApparatusOutstorageListController extends BaseController
{
    private String prefix = "wm/apparatus_outstorage";

    @Autowired
    private IWmApparatusOutstorageListService wmApparatusOutstorageListService;

    @RequiresPermissions("wm:apparatus_outstorage:view")
    @GetMapping()
    public String apparatus_outstorage()
    {
        return prefix + "/apparatus_outstorage";
    }

    /**
     * 查询医疗器械出库记录列表
     */
    @RequiresPermissions("wm:apparatus_outstorage:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(WmApparatusOutstorageList wmApparatusOutstorageList)
    {
        startPage();
        List<WmApparatusOutstorageList> list = wmApparatusOutstorageListService.selectWmApparatusOutstorageListList(wmApparatusOutstorageList);
        return getDataTable(list);
    }

    /**
     * 导出医疗器械出库记录列表
     */
    @RequiresPermissions("wm:apparatus_outstorage:export")
    @Log(title = "医疗器械出库记录", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(WmApparatusOutstorageList wmApparatusOutstorageList)
    {
        List<WmApparatusOutstorageList> list = wmApparatusOutstorageListService.selectWmApparatusOutstorageListList(wmApparatusOutstorageList);
        ExcelUtil<WmApparatusOutstorageList> util = new ExcelUtil<WmApparatusOutstorageList>(WmApparatusOutstorageList.class);
        return util.exportExcel(list, "apparatus_outstorage");
    }

    /**
     * 新增医疗器械出库记录
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存医疗器械出库记录
     */
    @RequiresPermissions("wm:apparatus_outstorage:add")
    @Log(title = "医疗器械出库记录", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(WmApparatusOutstorageList wmApparatusOutstorageList)
    {
        return toAjax(wmApparatusOutstorageListService.insertWmApparatusOutstorageList(wmApparatusOutstorageList));
    }

    /**
     * 修改医疗器械出库记录
     */
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap)
    {
        WmApparatusOutstorageList wmApparatusOutstorageList = wmApparatusOutstorageListService.selectWmApparatusOutstorageListById(id);
        mmap.put("wmApparatusOutstorageList", wmApparatusOutstorageList);
        return prefix + "/edit";
    }

    /**
     * 修改保存医疗器械出库记录
     */
    @RequiresPermissions("wm:apparatus_outstorage:edit")
    @Log(title = "医疗器械出库记录", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(WmApparatusOutstorageList wmApparatusOutstorageList)
    {
        return toAjax(wmApparatusOutstorageListService.updateWmApparatusOutstorageList(wmApparatusOutstorageList));
    }

    /**
     * 删除医疗器械出库记录
     */
    @RequiresPermissions("wm:apparatus_outstorage:remove")
    @Log(title = "医疗器械出库记录", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(wmApparatusOutstorageListService.deleteWmApparatusOutstorageListByIds(ids));
    }
}
